import { queryPageListApi, fetchTableListByDbIdApi,dataBaseDetail } from './service';

export default {
  namespace: 'database',
  state: {
    entityInfoObj: {},
    databaseList: [],
    tableList: [],
    databaseDetail:{},
  },

  effects: {
    *queryAllDatabase({ payload }, { call, put }) {
      const response = yield call(queryPageListApi, payload);
      yield put({
        type: 'changeDatabase',
        payload: response.data.rows,
      });
    },

    *queryTableListByDbId({ payload }, { call, put }) {
      const response = yield call(fetchTableListByDbIdApi, payload);
      yield put({
        type: 'changeTableList',
        payload: response.data,
      });
    },

    *queryDataDetail({ payload }, { call, put }) {
      console.log(payload)
      const response = yield call(dataBaseDetail, payload);
      yield put({
        type: 'dataDetail',
        payload: response.data,
      });
    },

  },


reducers: {
    changeDatabase(state, { payload }) {
      return {
        ...state,
        databaseList: payload,
      };
    },
  dataDetail(state, { payload }) {
    return {
      ...state,
      databaseDetail: payload,
    };
  },
    changeTableList(state, { payload }) {
      return {
        ...state,
        tableList: payload,
      };
    },
  },
};
